/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.gps.manager;

import java.sql.Connection;
import java.sql.SQLException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

/**
 *
 * @author romulogalindo
 */
public class ManagerDBPool {

    static Context context;

    static {
        try {
            context = (Context) (new InitialContext()).lookup("java:comp/env");
        } catch (NamingException ep) {
            System.out.println("Erroe al iniciar el manejador de conexion:" + ep.getMessage());
        }
    }

    public static Connection newConnection(String resource) {
        try {
            System.out.println("Contruyendo nueva conexion");
            Connection con = ((DataSource) context.lookup(resource)).getConnection();
            return con;
        } catch (NamingException | SQLException ep) {
            System.out.println("Danto una conexion:" + ep.getMessage());
            return null;
        }
    }

}
